<?php
class media_type {

	var $CI;
	var $media_type_model;

	public function __construct() {
		$this->CI =& get_instance();
		$this->CI->load->model("sys/sys_media_type_model");
		$this->media_type_model =$this->CI->sys_media_type_model;
	}

	public function get_media_types($parent_id) {
		return $this->media_type_model->query_media_types($parent_id);
	}

	public function save_media_type($media_type){
		$check_result=$this->check_media_type($media_type);
		if (!$check_result['result']) {
			return $check_result;
		}
		$media_type_id =$this->media_type_model->insert_media_type($media_type);
		$result['result']=true;
		$result['redirect_url']=base_url()."index.php/sys_relate_manage";
		return $result;
	}

	public function check_media_type($media_type,$media_type_id=""){
		$result['result'] =true;
		$result['message']="媒体类型名称可以使用";
		if ($media_type['media_type_name']=="") {
			$result['result']=false;
			$result['message']="媒体类型名称不能为空";
			return $result;
		}
		$media_type_info =$this->get_media_type_info_by_name($media_type['media_type_name']);
		if ($media_type_info=="") {
			$result['result']=true;
			$result['message']="媒体类型名称可以使用";
			return $result;
		}
		if ($media_type_info['media_type_id']!=$media_type_id) {
			$result['result']=false;
			$result['message']="媒体类型已经存在,请重新输入";
			return $result;
		}
		return $result;
	}


	public function query_media_type_info($media_type_id){
		return $this->media_type_model->query_media_type_info($media_type_id);
	}

	public function get_media_type_info_by_name($media_type_name){
		return $this->media_type_model->query_media_type_info_by_name($media_type_name);
	}

	public function set_delete_media_type($media_type_id){
		$this->media_type_model->set_delete_media_type($media_type_id);

	}
	public function update_media_type($media_type,$media_type_id){
		$check_result=$this->check_media_type($media_type,$media_type_id);
		if (!$check_result['result']) {
			return $check_result;
		}
		$media_type_id =$this->media_type_model->update_media_type($media_type,$media_type_id);
		$result['result']=true;
		$result['redirect_url']=base_url()."index.php/sys_relate_manage";
		return $result;
	}

	public function query_media_type_list(){
		$start		=	intval($this->CI->input->get("per_page"));
		$limit		=	$this->CI->config->item("page_size");
		return	$this->media_type_model->query_media_type_list($start,$limit);
	}

	public function query_media_type_num(){
		return $this->media_type_model->query_media_type_num();
	}
	public function get_all_media_type(){
		return $this->media_type_model->get_all_media_type();
	}
}
?>